//
//  WDViewController.m
//  项目A
//
//  Created by lanou3g on 15/8/30.
//  Copyright (c) 2015年 王钧. All rights reserved.
//

#import "WDViewController.h"
#import "MyViewController.h"
#import "GZViewController.h"
#import "SDImageCache.h"
#import "GYMyViewController.h"
#import "WDTableViewCell.h"
@interface WDViewController ()


@end

@implementation WDViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return 1;
            break;
        case 1 :
            return 2;
            break;
        case 2:
            return 2;
            break;
        case 3:
            return 1;
            break;
        case 4:
            return 1;
            break;
        default:
            break;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section < 1) {
        UITableViewCell *cellss = [tableView dequeueReusableCellWithIdentifier:@"cell_cc"];
        if (cellss == 0) {
            cellss = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell_cc"];
        }
        
        return cellss;
    }
     WDTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_ce" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
    if (indexPath.section == 1 && indexPath.row == 0) {
        cell.LabelTitel.text = @"我关注的单品";
        cell.imageView.image = [UIImage imageNamed:@"gift_Christmas_32px_520201_easyicon.net"];
        [cell setAccessoryType:1];
    }else if (indexPath.section == 1 && indexPath.row == 1)
    {
        cell.LabelTitel.text = @"我关注的主题";
        cell.imageView.image = [UIImage imageNamed:@"theme_32px_1176722_easyicon.net"];
        [cell setAccessoryType:1];
    }else if (indexPath.section == 2 && indexPath.row == 0 )
    {
        cell.LabelTitel.text = @"意见反馈";
        cell.imageView.image = [UIImage imageNamed:@"MAIL_EMAIL_30.679764243615px_1190266_easyicon.net"];
        [cell setAccessoryType:1];
    }else if (indexPath.section == 2 && indexPath.row == 1 )
    {
        cell.LabelTitel.text = @"清理缓存";
        cell.imageView.image = [UIImage imageNamed:@"mobi_livewallpaper_zwm_32px_1186851_easyicon.net"];
        [cell setAccessoryType:1];
    }else if (indexPath.section == 3 && indexPath.row == 0 )
    {
        cell.LabelTitel.text = @"关于我们";
        cell.imageView.image = [UIImage imageNamed:@"Game_Center_alt_32px_1184288_easyicon.net"];
        [cell setAccessoryType:1];
    }else if (indexPath.section == 4 && indexPath.row == 0)
    {
        cell.LabelTitel.text = @"设置";
        cell.imageView.image = [UIImage imageNamed:@"System_Pref_32px_1186265_easyicon.net"];
        [cell setAccessoryType:1];
    }
        return cell;
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            return 150;
            break;
            
        default:
            break;
    }
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当手指离开某行时，就让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.section == 1 && indexPath.row == 0) {
        UIStoryboard * story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        // 获取到指定根视图的画面，通过标记No.1
        GZViewController * gzvc = [story instantiateViewControllerWithIdentifier:@"No.2"];
        // push之前将tab bar隐藏。
        [gzvc setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:gzvc animated:YES];
    }else if (indexPath.section == 2 && indexPath.row == 1)
    {
        [[SDImageCache sharedImageCache] cleanDisk];
        [[SDImageCache sharedImageCache] clearMemory];
        NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
        // 打印缓存路径
        NSLog(@"================ %@",cachPath);
        dispatch_async(
                       dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
                       , ^{
                           NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
                           NSLog(@"%@", cachPath);
                           
                           NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
                           NSLog(@"files :%lu",(unsigned long)[files count]);
                           for (NSString *p in files) {
                               NSError *error;
                               NSString *path = [cachPath stringByAppendingPathComponent:p];
                               if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                                   [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                               }
                           }
                           [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];});
        UIAlertView *alret = [[UIAlertView alloc]initWithTitle:@"提示" message:@"清理完成！" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确认", nil];
        [alret show];
    }else if (indexPath.section == 3 && indexPath.row == 0)
    {
        UIStoryboard * story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        // 获取到指定根视图的画面，通过标记No.1
        GYMyViewController * vc = [story instantiateViewControllerWithIdentifier:@"GYWM"];
        [self.navigationController pushViewController:vc animated:YES];
    }
   
}

-(void)clearCacheSuccess
{
    NSLog(@"清理成功");
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
